package com.example.designpattern.lazyloading;

import lombok.extern.slf4j.Slf4j;

/**
 * 和HolderNaive功能一样，只是加了synchronized同步锁，
 * 是线程安全的，但是每次调用都会判断同步锁
 */
@Slf4j
public class HolderThreadSafe {

  private Gift gift;

  public HolderThreadSafe() {
  }

  public synchronized Gift getHeavy() {
    if (gift == null) {
      gift = new Gift();
    }
    return gift;
  }
}
